why Haskell can deduce [] type in this function

Posted by Sili on Stack Overflow See other posts from Stack Overflow or by Sili
Published on 2012-03-29T05:18:41Z Indexed on 2012/03/29 5:29 UTC
Read the original article Hit count: 100

Filed under:
|
rho x = map (((flip mod) x).(\a -> a^2-1)) (rho x)

This function will generate an infinite list. And I tested in GHCi, the function type is

*Main> :t rho
rho :: Integral b => b -> [b]

If I define a function like this

fun x = ((flip mod) x).(\a -> a^2-1)

The type is

*Main> :t fun
fun :: Integral c => c -> c -> c

My question is, how can Haskell deduce the function type to b -> [b]? We don't have any [] type data in this function. Thanks!

© Stack Overflow or respective owner

Related posts about haskell

Related posts about types